#include <bits/stdc++.h>
using namespace std;
int read();
int x,pma=-1,t,n,m,l,v,dc[100005],vc[100005],ac[100005],p[1000005],s=0,g,lc;
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	t=read();
	while(t--){
		s=0;pma=-1;
		n=read();m=read();l=read();v=read();
		g=m;lc=0;
		for(int i=1;i<=n;i++){
			dc[i]=read();vc[i]=read();ac[i]=read();
		}
		for(int i=1;i<=m;i++){
			x=read();p[x]++;
			pma=max(pma,x);
		}
		for(int i=2;i<=pma;i++){
			p[i]+=p[i-1];
		}
		for(int i=1;i<=n;i++){
			if(ac[i]==0&&vc[i]>v&&dc[i]<=pma){s++;g=m-1;}
			else if(ac[i]>0&&dc[i]<=pma){
				lc=(v*v-vc[i]*vc[i])/(2*ac[i]);
				if(lc<0){s++;}
				else if(dc[i]+lc+1<=pma){s++;}
				g=m-1;
			}
		}
		cout<<s<<" "<<g<<endl;
	}
	return 0;
}
int read(){
	int x=0,f=1;char c;
	while(!isdigit(c=getchar()))if(c=='-')f=-1;
	x=(c^48);
	while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+(c^48);
	return x*f;
}
 
